/*
 * IcmpErrorSessionManager.cpp
 *
 *  Created on: 28/08/2011
 *      Author: george
 */

#include "icmperrorsessionmanager.h"

IcmpErrorSessionManager::IcmpErrorSessionManager() {
}

IcmpErrorSessionManager::~IcmpErrorSessionManager() {
}

IcmpErrorSession *IcmpErrorSessionManager::getSession(in_addr *src,in_addr *dst){
	unsigned pos = 0;

	while (pos < session.size() ){
		bool mesmo_src = (session[pos]->src.s_addr == src->s_addr);
		bool mesmo_dst = (session[pos]->dst.s_addr == dst->s_addr);

		if ( mesmo_dst && mesmo_src )
		{

			return session[pos];
		}

		++pos;
	}

	session.push_back(new IcmpErrorSession(*src, *dst));

	return session[pos];
}


bool IcmpErrorSessionManager::add(struct in_addr *src, struct in_addr *dst, icmp_hdr_t *p){
	IcmpErrorSession* icmperrorsession = getSession(src, dst);
	icmperrorsession->add(p);
	return true;
}
